<?php
namespace app\index\controller;

use app\common\controller\Base;
use app\index\model\User;
use think\Controller;

class Account extends Base
{
    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->model = new User();
    }
    /**
     * 登录
     */
    public function doLogin()
    {

        try {

            //====================
            //值过滤，预防注入攻击
            //====================
            $username = addslashes(htmlspecialchars(input('?request.user') ? trim(input('user')) : ''));
            $password = addslashes(htmlspecialchars(input('?request.pass') ? trim(input('pass')) : ''));

            $output = $this->model->login($username, $password);
            return json($output);

        } catch (\Exception $e) {
            throw new \think\Exception('异常消息:' . $e->getMessage());
        }
    }
    /**
     * 登出
     */
    public function doLogout()
    {
        $output = $this->model->doLogout();
        return json($output);
    }
    /**
     * 保持会话
     */
    public function keepSessionAlive()
    {

        session_start();

        $output = array('success' => true, 'msg' => "会话保持成功！");
        _callback($output);
    }
    /**
     * 修改密码
     */
    public function doChangePass()
    {
        $user    = input('post.user/s');
        $oldpass = input('post.oldpass/s');
        $newpass = input('post.newpass/s');

        $output = $this->model->doChangePass($user, $oldpass, $newpass);
        _callback($output);
    }

    /**
     * 修改密码
     */
    public function getChangePass($oldpass)
    {
        $newpass = $this->model->setPassAttr($oldpass);
        //dump($newpass);
    }
}
